//
//  AViewController.m
//  ProductDetail
//
//  Created by Adiljan on 2016/10/27.
//  Copyright © 2016年 Adiljan. All rights reserved.
//

#import "AViewController.h"
#import "STPhotoBroswer.h"


#define MaxSCale 2.0  //最大缩放比例
#define MinScale 0.5  //最小缩放比例

@interface AViewController ()<UIGestureRecognizerDelegate>
{
    CGFloat lastScale;
}
@property (weak, nonatomic) IBOutlet UIImageView *imageView;
@property (nonatomic,assign) CGFloat totalScale;

@end

@implementation AViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    UIView *v = [[UIView alloc]initWithFrame:self.view.bounds];
    v.backgroundColor = [UIColor blueColor];
    [self.view addSubview:v];
    
    UIImageView *image = [[UIImageView alloc]initWithFrame:CGRectMake(10, 100, 300, 300)];
    image.backgroundColor = [UIColor redColor];
    self.imageView = image;
    self.imageView.image = [UIImage imageNamed:@"ad"];
    [v addSubview:self.imageView];
    self.totalScale = 1.0;
    
    UIPinchGestureRecognizer *pinch = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(pinch:)];
    [self.imageView addGestureRecognizer:pinch];
    
    
    
}



- (void)pinch:(UIPinchGestureRecognizer *)recognizer{
    
    CGFloat scale = recognizer.scale;
    
    //放大情况
    if(scale > 1.0){
        if(self.totalScale > MaxSCale) return;
    }
    
    //缩小情况
    if (scale < 1.0) {
        if (self.totalScale < MinScale) return;
    }
    
    self.imageView.transform = CGAffineTransformScale(self.imageView.transform, scale, scale);
    self.totalScale *=scale;
    recognizer.scale = 1.0;
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
